package com.pengtu.service.contract;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.pengtu.dao.Page;
import com.pengtu.dao.QueryFilter;
import com.pengtu.dao.contract.AccordingDao;
import com.pengtu.dao.contract.DocumentDao;
import com.pengtu.dao.contract.InventorDao;
import com.pengtu.dao.contract.ItemListDao;
import com.pengtu.entity.contract.According;
import com.pengtu.entity.contract.Document;
import com.pengtu.entity.contract.Inventor;
import com.pengtu.entity.contract.Itemlist;
import com.pengtu.service.BaseManager;

@Component
@Transactional
public class AccordingManager extends BaseManager{
	private AccordingDao accordingDao;
	private DocumentDao documentDao;
	private InventorDao inventorDao;
	private ItemListDao itemlistDao;

	@Autowired
	public void setAccordingDao(AccordingDao accordingDao) {
		this.accordingDao = accordingDao;
	}

	@Autowired
	public void setDocumentDao(DocumentDao documentDao) {
		this.documentDao = documentDao;
	}
	
	@Autowired
	public void setInventorDao(InventorDao inventorDao) {
		this.inventorDao = inventorDao;
	}

	@Autowired
	public void setItemlistDao(ItemListDao itemlistDao) {
		this.itemlistDao = itemlistDao;
	}
	//----------------------建设工程检测协议书检测依据-------------------------s
	@Transactional(readOnly=true)
	public void saveAccording(According according){
		accordingDao.save(according);
	}
	
	@Transactional(readOnly=true)
	public Page<According> findPageAccor(final Page<According> page,final QueryFilter fileter){
		
		return accordingDao.findPage(page, fileter);
	}
	@Transactional(readOnly=true)
	public According findAccorByValue(String propertyName,String value){
		if(propertyName.equalsIgnoreCase("id")){
			return accordingDao.get(value);
		}
		return accordingDao.findUniqueBy(propertyName, value);
	}
	//---------------------建设工程检测协议书-------------------------------
	@Transactional(readOnly=true)
	public Page<Document> findPageDocument(final Page<Document> page,final QueryFilter fileter){
		
		return documentDao.findPage(page, fileter);
	}
	@Transactional(readOnly=true)
	public Document findDocumentByValue(String propertyName,String value){
		if(propertyName.equalsIgnoreCase("id")){
			return documentDao.get(value);
		}
		return documentDao.findUniqueBy(propertyName, value);
	}
	
	
	public void saveDocument(Document document){
		 documentDao.save(document);
	}
	//---------------------检测项目清单--------------------------------------
	@Transactional(readOnly=true)
	public Itemlist findItemlistByValue(String propertyName,String value){
		if(propertyName.equalsIgnoreCase("id")){
			return itemlistDao.get(value);
		}
		return itemlistDao.findUniqueBy(propertyName, value);
	}
	@Transactional(readOnly=true)
	public List<Itemlist> findItemlistAll(){
		return itemlistDao.getAll();
	}
	@Transactional(readOnly=true)
	public Itemlist getItemlistById(String id){

		return itemlistDao.get(id);
	}
	
	@Transactional(readOnly=true)
	public void saveItemlist(Itemlist itemlist){
		itemlistDao.save(itemlist);
	}
	//------------------检测费用清单---------------------------------
	@Transactional(readOnly=true)
	public List<Inventor> getInventor(){
		return inventorDao.getAll();
	}
	@Transactional(readOnly=true)
	public Inventor findInventorByValue(String propertyName,String value){
		if(propertyName.equalsIgnoreCase("id")){
			return inventorDao.get(value);
		}
		return inventorDao.findUniqueBy(propertyName, value);
	}
	@Transactional(readOnly=true)
	public List<Inventor> findInventor(String propertyName,String value){
		return inventorDao.findBy(propertyName, value);
	}
	public void saveInventor(Inventor inventor){
		inventorDao.save(inventor);
	}

	public void saveAccordingList(List<According> accordingList) {
		for (int i = 0; i < accordingList.size(); i++) {
			According according = accordingList.get(i);
			saveAccording(according);
		}
		
	}

	public List<According> findAccordingList(Document document) {
		
		return accordingDao.findBy("document", document);
	}

	public List<Inventor> findInventorOrdById(String string, String cid) {
		return inventorDao.findBy("cid", cid, "branchCode", true);
	}

	public void deleteAccordCid(String cid) {
		accordingDao.deleteAccordCid(cid);
	}

	public void deleteInventorCid(String cid) {
		inventorDao.deleteInventorCid(cid);
	}

	public void deleteInventor(String cid, String codeed) {
		inventorDao.deleteInventor(cid, codeed);
		
	}
}
